package queue;


import list.LinkedListImplementation;

import java.util.NoSuchElementException;

public class LinkedListQueue<E> implements Queue<E>{

    private LinkedListImplementation<E> queue;

    public LinkedListQueue(){
        queue = new LinkedListImplementation<>();
    }

    @Override
    public E element() {
        if (queue.size() == 0)
            throw new NoSuchElementException("Queue is empty");
        return queue.getFirst();
    }

    @Override
    public boolean offer(E e) {
        queue.add(e);
        return true;
    }

    @Override
    public E peek() {
        return queue.getFirst();
    }

    @Override
    public E poll() {
        if (queue.size() == 0)
            return null;
        E head = queue.getFirst();
        queue.remove(head);
        return head;
    }

    @Override
    public E remove() {
        if (queue.size() == 0)
            throw new NoSuchElementException("Queue is empty.");
        E head = queue.getFirst();
        queue.remove(head);
        return head;
    }
}
